package com.xfsg.core.elasticjob;

import com.yomahub.tlog.core.rpc.TLogLabelBean;
import com.yomahub.tlog.core.rpc.TLogRPCHandler;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

/**
 * @author ZhangYi
 * @version 1.0.0
 * @Description:
 * @date 2022/3/30
 */
@Aspect
public class LogTraceElasticJobAop {

    private final TLogRPCHandler tLogRPCHandler = new TLogRPCHandler();


    @Pointcut("execution(public * com.dangdang.ddframe.job.api.simple.SimpleJob.execute(..))")
    private void anyJobExecution() {
    }

    @Around("anyJobExecution()")
    public Object wrapJobExecution(ProceedingJoinPoint pjp) throws Throwable {
        try {
            tLogRPCHandler.processProviderSide(new TLogLabelBean());
            return pjp.proceed();
        } finally {
            tLogRPCHandler.cleanThreadLocal();
        }
    }

}
